package com.jzhao.jpre.model.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import com.jzhao.jpre.base.StringPublicDeal;
import com.jzhao.jpre.model.BusiType;

public class BusiTypeDao {
	protected JdbcTemplate jdbcTemplate;
	protected StringPublicDeal strPubDeal;

	class BusiTypeRowMapper implements RowMapper {
		public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
			BusiType busiType = new BusiType();
			busiType.setBusiType(strPubDeal.trim(rs.getString("busiType")));
			busiType.setBusiName(strPubDeal.trim(strPubDeal.convToGB2312(rs.
					getString("busiName"))));
			busiType.setMemo(strPubDeal.trim(strPubDeal.convToGB2312(rs.
					getString("memo"))));
			
			return busiType;
		}
	}
	
	public void setDataSource(DataSource dataSource) {
		jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	public void setStrPubDeal(StringPublicDeal strPubDeal) {
		this.strPubDeal = strPubDeal;
	}
	
	public BusiType selectByBusiType(String id) throws DataAccessException {
		BusiType busiType=null;
		String sql = "SELECT * FROM t_js_busi_type WHERE busiType='" + id.trim() + "'";
		busiType = (BusiType) jdbcTemplate.queryForObject(sql,new BusiTypeRowMapper());
		return busiType;
	}
}
